import 'package:flutter/material.dart';

/// 渐变卡片组件 - Gradient card component
/// 
/// 基于最新Flutter UI设计最佳实践，提供美观的渐变背景卡片
/// Based on latest Flutter UI design best practices, providing beautiful gradient background cards
class GradientCard extends StatelessWidget {
  final Widget child;
  final List<Color> colors;
  final AlignmentGeometry begin;
  final AlignmentGeometry end;
  final double borderRadius;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final double? width;
  final double? height;
  final List<BoxShadow>? boxShadow;
  final VoidCallback? onTap;

  const GradientCard({
    super.key,
    required this.child,
    required this.colors,
    this.begin = Alignment.topLeft,
    this.end = Alignment.bottomRight,
    this.borderRadius = 16.0,
    this.padding,
    this.margin,
    this.width,
    this.height,
    this.boxShadow,
    this.onTap,
  });

  /// 预设的紫色渐变卡片 - Preset purple gradient card
  factory GradientCard.purple({
    required Widget child,
    EdgeInsetsGeometry? padding,
    EdgeInsetsGeometry? margin,
    double? width,
    double? height,
    VoidCallback? onTap,
  }) {
    return GradientCard(
      colors: const [
        Color(0xFF8B5CF6), // 紫色 - Purple
        Color(0xFF4C1D95), // 深紫色 - Deep purple
      ],
      padding: padding,
      margin: margin,
      width: width,
      height: height,
      onTap: onTap,
      boxShadow: [
        BoxShadow(
          color: const Color(0xFF8B5CF6).withOpacity(0.3),
          blurRadius: 12,
          offset: const Offset(0, 6),
        ),
      ],
      child: child,
    );
  }

  /// 预设的金色渐变卡片 - Preset gold gradient card
  factory GradientCard.gold({
    required Widget child,
    EdgeInsetsGeometry? padding,
    EdgeInsetsGeometry? margin,
    double? width,
    double? height,
    VoidCallback? onTap,
  }) {
    return GradientCard(
      colors: const [
        Color(0xFFF59E0B), // 金色 - Gold
        Color(0xFFD97706), // 深金色 - Deep gold
      ],
      padding: padding,
      margin: margin,
      width: width,
      height: height,
      onTap: onTap,
      boxShadow: [
        BoxShadow(
          color: const Color(0xFFF59E0B).withOpacity(0.3),
          blurRadius: 12,
          offset: const Offset(0, 6),
        ),
      ],
      child: child,
    );
  }

  /// 预设的蓝色渐变卡片 - Preset blue gradient card
  factory GradientCard.blue({
    required Widget child,
    EdgeInsetsGeometry? padding,
    EdgeInsetsGeometry? margin,
    double? width,
    double? height,
    VoidCallback? onTap,
  }) {
    return GradientCard(
      colors: const [
        Color(0xFF3B82F6), // 蓝色 - Blue
        Color(0xFF1E3A8A), // 深蓝色 - Deep blue
      ],
      padding: padding,
      margin: margin,
      width: width,
      height: height,
      onTap: onTap,
      boxShadow: [
        BoxShadow(
          color: const Color(0xFF3B82F6).withOpacity(0.3),
          blurRadius: 12,
          offset: const Offset(0, 6),
        ),
      ],
      child: child,
    );
  }

  /// 预设的透明卡片 - Preset transparent card
  factory GradientCard.transparent({
    required Widget child,
    EdgeInsetsGeometry? padding,
    EdgeInsetsGeometry? margin,
    double? width,
    double? height,
    VoidCallback? onTap,
  }) {
    return GradientCard(
      colors: [
        Colors.white.withOpacity(0.1),
        Colors.white.withOpacity(0.05),
      ],
      padding: padding,
      margin: margin,
      width: width,
      height: height,
      onTap: onTap,
      boxShadow: [
        BoxShadow(
          color: Colors.black.withOpacity(0.1),
          blurRadius: 8,
          offset: const Offset(0, 4),
        ),
      ],
      child: child,
    );
  }

  @override
  Widget build(BuildContext context) {
    Widget cardWidget = Container(
      width: width,
      height: height,
      margin: margin,
      padding: padding ?? const EdgeInsets.all(16),
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: begin,
          end: end,
          colors: colors,
        ),
        borderRadius: BorderRadius.circular(borderRadius),
        boxShadow: boxShadow ?? [
          BoxShadow(
            color: colors.first.withOpacity(0.2),
            blurRadius: 8,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: child,
    );

    if (onTap != null) {
      return GestureDetector(
        onTap: onTap,
        child: cardWidget,
      );
    }

    return cardWidget;
  }
}

/// 玻璃态卡片组件 - Glassmorphism card component
/// 
/// 提供现代化的玻璃态效果卡片
/// Provides modern glassmorphism effect cards
class GlassCard extends StatelessWidget {
  final Widget child;
  final double borderRadius;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final double? width;
  final double? height;
  final VoidCallback? onTap;
  final double opacity;
  final double blurRadius;

  const GlassCard({
    super.key,
    required this.child,
    this.borderRadius = 16.0,
    this.padding,
    this.margin,
    this.width,
    this.height,
    this.onTap,
    this.opacity = 0.1,
    this.blurRadius = 10.0,
  });

  @override
  Widget build(BuildContext context) {
    Widget cardWidget = Container(
      width: width,
      height: height,
      margin: margin,
      padding: padding ?? const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: Colors.white.withOpacity(opacity),
        borderRadius: BorderRadius.circular(borderRadius),
        border: Border.all(
          color: Colors.white.withOpacity(0.2),
          width: 1,
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.1),
            blurRadius: blurRadius,
            offset: const Offset(0, 4),
          ),
        ],
      ),
      child: child,
    );

    if (onTap != null) {
      return GestureDetector(
        onTap: onTap,
        child: cardWidget,
      );
    }

    return cardWidget;
  }
}